<?php
/**
 * Created by PhpStorm.
 * Author: Lin
 * Date: 2017/12/22
 * Time: 15:49
 */

if (! function_exists('debug_log')) {
    /**
     * 将调试信息写入文件
     * @param $msg
     */
    function debug_log($msg, $fileName = 'debug') {
        $format = "[%datetime%] %channel%.%level_name%: %message%\n";
        $formatter = new \Monolog\Formatter\LineFormatter($format, null, true, true);
        $file = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
        $stream = new \Monolog\Handler\StreamHandler(LOG_PATH.$fileName.'.log', \Monolog\Logger::DEBUG);
        $stream->setFormatter($formatter);
        $logger = new \Monolog\Logger('debug');
        $logger->pushHandler($stream);
        $logger->info($file[0]['file'].':'.$file[0]['line'].'->'.$file[1]['function']);
        $logger->addDebug(print_r($msg, true));
    }
}